const { Schema } = require('./config')
// 声明mogoose的特殊数据类型objectId
const objectId = Schema.Types.ObjectId

const commentSchema = new Schema({
  content: String,
  from: {
    type: objectId,
    ref: "users", // 关联users表
    avatar: String,
    username: String
  },
  article: {
    type: objectId,
    ref: "articles" // 关联articles表
  }
}, {
  timestamps: {
    // 配置文章创建时间
    createdAt: "created"
  }
})

module.exports = commentSchema